package com.project.structures.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;

public class FileUtils {
	
	private static String filePath;
	
	public static String readFile(String path) {
		String result = "";

		try {
			result = org.apache.tools.ant.util.FileUtils.readFully(new FileReader(path));
		} catch (FileNotFoundException e) {

		} catch (IOException e) {
			
		}
			
		return result;		
	}
	
	public static void writeFile(String fileName, String content){
		File file = new File(getFilePath() + fileName);
		
		Writer writer = null;
        try {
        	writer = new FileWriter(file);
            writer.write(content);
            
        } catch (IOException e) {
            //TODO LOG
        } finally {
			try {
				if (writer != null) {
					writer.close();
				}
			} catch (Exception e) {
				//LOG
			}
		}
	}
	
	public static Boolean existsFile(String fileName) {
		File file = new File(filePath + fileName);
		
		return file.exists();
	}

	/**
	 * @return the filePath
	 */
	public static String getFilePath() {
		return FileUtils.filePath;
	}

	/**
	 * @param filePath the filePath to set
	 */
	public static void setFilePath(String filePath) {
		FileUtils.filePath = filePath;
	}
	
}
